package juf.adapter;

import java.awt.Dimension;

import javax.swing.JCheckBox;
import juf.*;


/**Binding between a JCheckBox component and a Property data source
 * 
 * @author Dale Halliwell
 *
 */
@SuppressWarnings("serial")
public class JCheckBoxAdapter extends AbstractAdapter implements Adapter {

	
	public JCheckBoxAdapter(Property property) { 
		if (property.getValue() instanceof Boolean)
			this.component = new JCheckBox("", ((Boolean) property.getValue()).booleanValue());
		else
			throw new IllegalArgumentException("JCheckBoxAdapter only accepts bindings to members of type Boolean/boolean");
			
		bind(property, new Dimension(350,30));
	}

	/* (non-Javadoc)
	 * @see juf.adapter.AbstractAdapter#refresh()
	 */
	public void refresh(){		
		if (!(property.getValue() == null))
			((JCheckBox)component).setSelected((Boolean) property.getValue());
	}


	/* (non-Javadoc)
	 * @see juf.adapter.AbstractAdapter#save()
	 */
	public void save(){
		property.setValue(((JCheckBox)component).isSelected());
	}



}
